﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.MT3DMS.DomainLayer;

using HA.ModFlow.Infrastructure;

using HA.ModFlow.Controls;
using HA.Data;

namespace HA.ModFlow.Controls.MT3DMSWindows
{
    /// <summary>
    /// winDispersion.xaml 的交互逻辑
    /// </summary>
    public partial class winDispersion : Window
    {
        public winDispersion(Project proj)
        {
            InitializeComponent();
            project = proj;
            MT3DMSData mtdata = proj.Mt3dmsData;
            this._Disper =(Dispersion) mtdata.Dispersion.Clone();
            this._mdOption = mtdata.BasicTransport.ModelOption;
            this.label6.Content = "有效分子扩散系数(" + HA.ModFlow.Domain.DomainLayer.UnitConverter.GetLength(mtdata.BasicTransport.ModelOption.Units.Length) + "^2/" + HA.ModFlow.Domain.DomainLayer.UnitConverter.GetTime(mtdata.BasicTransport.ModelOption.Units.Time) + ")";
            this.btnLongitDisper.Content = "纵向弥散系数(" + HA.ModFlow.Domain.DomainLayer.UnitConverter.GetLength(mtdata.BasicTransport.ModelOption.Units.Length) + ")";

            MenuItem itemCopy = new MenuItem();
            itemCopy.Header = "复制";
            itemCopy.Command = ApplicationCommands.Copy;

            //MenuItem itemPaste2 = new MenuItem();
            //itemPaste2.Header = "粘贴";
            //itemPaste2.InputGestureText = "Ctrl+V";
            //itemPaste2.Click += new RoutedEventHandler(itemPaste2_Click);

            ContextMenu cm = new ContextMenu();
            cm.Items.Add(itemCopy);
            //cm.Items.Add(itemPaste2);          
            this.dtgrid.ContextMenu = cm;
        }

        Project project;
        MTModelOption _mdOption;
        private Dispersion _Disper;

        public Dispersion Disper
        {
            get { return _Disper; }           
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.dtgrid .ItemsSource  = this.Disper.DisperChild;
          
        }

        private void btnLongitDisper_Click(object sender, RoutedEventArgs e)
        {
            //winLongDisper Win = new winLongDisper(this ._Disper );
            //Win.Owner = this;
            //Win.ResizeMode = ResizeMode.NoResize;
            //Win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //Win.ShowDialog();

            int nlayers=this._Disper.AL.Count;
            int nrows=this._Disper.AL[0].GetLength(0);
            int ncols=this._Disper.AL[0].GetLength(1);

            CellCenterDataSet3d ds = new CellCenterDataSet3d(this._Disper.AL,null,nrows,ncols,nlayers);

            ds.Label = "纵向弥散系数";

            winCellCenterDSEdit win = new winCellCenterDSEdit(ds,project);
            win.Owner = this;
            win.ResizeMode = ResizeMode.NoResize;
            win.Unit += "(" + HA.ModFlow.Domain.DomainLayer.UnitConverter.GetLength(_mdOption.Units.Length) + ")";
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (win.ShowDialog() == true)
            {
                this._Disper.SetAL(win.PcDs.Dataset.ToListData ());
                if (project.CurrentDSData != null && project.CurrentDSData.Label == ds.Label)
                    project.OnCurrentDSChanged();

            }





        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void dtgrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = (e.Row.GetIndex() + 1).ToString();
        }
    }
}
